package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 搜索
     * */
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrdersPageQueryDTO dto){
        PageResult pageResult = orderService.search(dto);
        return Result.success(pageResult);
    }

    /**
     * 统计订单数量
     * */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        return Result.success(orderService.statistics());
    }

    /**
     * 订单详情
     * */
    @GetMapping("details/{id}")
    public Result<OrderVO> details(@PathVariable("id") Long id){
        return Result.success(orderService.orderDetail(id));
    }

    /**
     * 接单
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        orderService.confirm(dto.getId());
        return Result.success();
    }
    /**
     * 拒单
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        orderService.rejection(dto.getId(), dto.getRejectionReason());
        return Result.success();
    }

    /**
     * 取消
     * */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        orderService.cancel(dto.getId(), dto.getCancelReason());
        return Result.success();
    }


    /**
     * 派送
     * */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成
     * */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id){
        orderService.complete(id);
        return Result.success();
    }


}